package com.dodayum.controller;

import com.dodayum.entity.NginxLogInfo;
import com.dodayum.service.MyEntityEasyService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @version 1.0
 * 备注：
 * @Author BaiYu
 * </br>@Date 2024/12/26 16:34
 */

@RestController
@RequestMapping("/esEasyDemo")
public class MyEntityEasyController {

    @Resource
    private MyEntityEasyService myEntityEasyService;

    @GetMapping("/findAll")
    public List<NginxLogInfo> findAll() {
        Iterable<NginxLogInfo> all = myEntityEasyService.findAll();
        List<NginxLogInfo> response = new ArrayList<>();
        all.forEach(response::add);
        return response;
    }

    @GetMapping("/findById")
    public NginxLogInfo findById(@RequestParam("id") String id) {
        return myEntityEasyService.findById(id);
    }

    @PostMapping("/save")
    public NginxLogInfo save(@RequestBody NginxLogInfo nginxLogInfo) {
        return myEntityEasyService.save(nginxLogInfo);
    }

    @GetMapping("/delete")
    public void delete(@RequestParam("id") String id) {
        myEntityEasyService.deleteById(id);
    }

    @PostMapping("/updateById")
    public NginxLogInfo updateById(@RequestParam("id") String id, @RequestBody NginxLogInfo nginxLogInfo) throws Exception {
        return myEntityEasyService.updateById(id, nginxLogInfo);
    }

    @GetMapping("/deleteAll")
    public void deleteAll() {
        Iterable<NginxLogInfo> all = myEntityEasyService.findAll();
        all.forEach(myEntity -> myEntityEasyService.deleteById(myEntity.getId()));
    }

}
